package org.umss.fixture.activities;

import org.umss.fixture.R;
import org.umss.fixture.services.FixtureBuilderServices;

import android.app.Activity;
import android.app.ProgressDialog;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

public class NewPhaseActivity extends Activity {

    private static ProgressDialog progressDialog;
    private String championshipName;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_new_phase);
        Bundle bundle = getIntent().getExtras();
        championshipName = bundle.getString("CHAMPIONSHIP_NAME");
        final Button button = (Button) findViewById(R.id.create_phase);
        button.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                //new SavePhaseTask().execute();
            }
        });
    }

    private class SavePhaseTask extends AsyncTask<Void, Void, Void> {

        @Override
        public void onPreExecute() {
            if (progressDialog != null) {
                progressDialog.setIndeterminate(true);
                progressDialog.setCancelable(false);
                progressDialog.setMessage("Saving phase...");
                progressDialog.show();
            }
        }

        @Override
        protected Void doInBackground(Void... params) {
            FixtureBuilderServices services = new FixtureBuilderServices();
            services.savePhase(championshipName);
            return null;
        }

        @Override
        protected void onPostExecute(Void result) {
            finish();
            if (progressDialog != null) {
                progressDialog.dismiss();
            }

            progressDialog = null;
        }
    }

}
